package com.github.yealove.configgen.service.impl;

import com.github.yealove.configgen.mapper.TemplateMapper;
import com.github.yealove.configgen.model.Template;
import com.github.yealove.configgen.service.TemplateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TemplateServiceImpl implements TemplateService {
    @Autowired
    private TemplateMapper templateMapper;

    @Override
    public List<Template> getAllTemplate() {
        return templateMapper.getAllTemplate();
    }

    @Override
    public void saveTemplate(Template template) {
        if (template.getId() == 0) {
            templateMapper.addTemplate(template);
        } else {
            templateMapper.updateTemplate(template);
        }
    }

    @Override
    public Template getTemplateById(int templateId) {
        return templateMapper.getTemplateById(templateId);
    }
}
